/**
 *
 * @type {module:path}
 */
const path = require('path')
const fs = require('fs')



//需要抓取的城市数据
const need_fetch_cities = [ { name:'chengdu',url: 'http://www.dianping.com/shoplist/search/8_10_0_score '},{
  name: 'beijing',url: 'http://www.dianping.com/shoplist/search/2_10_0_score'
},  { name: 'guangzhou' ,url: 'http://www.dianping.com/shoplist/search/4_10_0_score'},
  { name: 'shenzhen', url: 'http://www.dianping.com/shoplist/search/7_10_0_score'},]

for (const city of need_fetch_cities) {
  let p = path.join(process.cwd(), 'cities1', `${city.name}.json`);
  let writeStream = fs.createWriteStream(path.join(process.cwd(),'cities1', `${city.name}_native.json`))
  if(fs.existsSync(p)){
    let data = require(p);
    if(data.shopBeans && data.shopBeans.length > 0){
      let obj = Object.create(null);
      obj.city_name = city.name;
      obj.shops = [];
      for (let shop of data.shopBeans) {
        obj.shops.push(`http://www.dianping.com/shop/${shop.shopId}`) ;
      }
      writeStream.write(JSON.stringify(obj));
      writeStream.end();
    }
  }
}